﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using System.Configuration;

namespace RN.ERP.Web.Enterprise
{
    public partial class EnterpriseFinancialInfo : BasePage
    {
        #region 参数

        public override bool IsCheckPermission
        {
            get
            {
                return false;
            }
        }

        public string CorpUserGuid
        {
            get
            {
                string corpUserGuid = string.Empty;
                if (Request.QueryString["corpUserGuid"] != null)
                {
                    corpUserGuid = Request.QueryString["corpUserGuid"];
                }
                else
                {
                    corpUserGuid = UserInfo.CorpUserGuid;
                }
                return corpUserGuid;
            }
        }

        public string RoleType
        {
            get
            {
                return UserInfo.RoleType;
            }
        }


        ///当前市场
        protected string CurrentArea
        {
            get
            {
                return ConfigurationManager.AppSettings["sysArea"];
            }
        }
        protected string NowYear
        {
            get
            {
                return DateTime.Now.ToString("yyyy");
            }
        }
        protected string LastYear
        {
            get
            {
                return DateTime.Now.AddYears(-1).ToString("yyyy");
            }
        }
        protected string BeforeLastYear
        {
            get
            {
                return DateTime.Now.AddYears(-2).ToString("yyyy");
            }
        } 
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Context.Request["status"]))
                {
                    hdStatus.Value = Context.Request["status"];
                }
                if (!string.IsNullOrEmpty(Context.Request["mid"]))
                {
                    hdID.Value = Context.Request["mid"];
                }
                Initial();
            }
        }

        /// <summary>
        /// 根据ID获取企业财务基本信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private void GetFinancialInfoByID()
        {
            try
            {
                int id = Convert.ToInt32(Context.Request["mid"]);
                EnterpriseService.EnterpriseServiceClient client = new EnterpriseService.EnterpriseServiceClient();
                string result = client.GetCorpFinancialInfoByID(new Guid(), id, CurrentArea);
                string rst = JsonConvert.SerializeObject(new { Result = result, Message = "获取成功" });
                OutputData(rst);
            }
            catch (Exception ex)
            {
                string rst = JsonConvert.SerializeObject(new { Result = false, Message = "获取失败" });
                OutputData(rst);
            }
        }

        /// <summary>
        /// 输出JSON格式数据到页面
        /// </summary>
        /// <param name="dataStr"></param>
        private void OutputData(string dataStr)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(dataStr);
            HttpContext.Current.Response.End();
        }

        #region 页面初始化
        private void Initial()
        {
            if (hdStatus.Value == "0")
            {
                txtID.Visible = false;
            }
        }

        #endregion
    }
}